﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.FileOperate
{
    public static class FileHelper
    {
        public static string ReadFile(string filepath)
        {
            StreamReader sr = new StreamReader(filepath, Encoding.Default);
            String line;
            string jsonobj = "";
            while ((line = sr.ReadLine()) != null)
            {
                jsonobj = jsonobj + line.ToString();
            }
            sr.Close();
            return jsonobj;
        }
        public static void WriteFile(string filepath, string str)
        {
            try
            {
                FileStream fs = new FileStream(filepath, FileMode.Create);
                //获得字节数组
                byte[] data = System.Text.Encoding.Default.GetBytes(str);
                //开始写入
                fs.Write(data, 0, data.Length);
                //清空缓冲区、关闭流
                fs.Flush();
                fs.Close();
            }
            catch (Exception ex)
            {


            }

        }
    }
}
